package com.metal.gear.certification.controller;

import com.metal.gear.common.entity.Result;
import com.metal.gear.common.exception.SzlBusinessException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/sys/authentication")
@Tag(name = "0.身份认证")
public class AuthenticationController {


    @Operation(summary = "当前用户")
    @GetMapping(value = "/currentUser")
    public Result<Boolean> currentUser() {
        throw new SzlBusinessException("接口未实现");
    }

    @Operation(summary = "当前用户名称")
    @GetMapping("/current/username")
    public Result<String> currentUserName0() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String currentPrincipalName = authentication.getName();
        return Result.ok(currentPrincipalName);
    }


    @Operation(summary = "执行认证")
    @PostMapping(value = "/doLogin")
    public Result<Boolean> doLogin(String username, String password) {
        return Result.ok("执行认证成功！！");
    }

    @Operation(summary = "登出")
    @GetMapping(value = "/logout")
    public void logout() {
    }


}
